package com.example.springbootdisconf.callback;

import com.baidu.disconf.client.common.annotations.DisconfUpdateService;
import com.baidu.disconf.client.common.update.IDisconfUpdate;
import com.example.springbootdisconf.config.RedisConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 更新配置时的回调函数
 */
@Component
@DisconfUpdateService(classes = {RedisConfig.class})
public class SimpleDemoServiceUpdateCallback implements IDisconfUpdate {
    @Autowired
    private SimpleDemoService simpleDemoService;

    /**
     * 每次更新配置都会调reload方法
     *
     * @throws Exception
     */
    public void reload() throws Exception {
        System.out.println("redis配置文件更新了，你可以在这里做一些事：比如更新Redis连接等等");
        simpleDemoService.change();
    }
}
